// secondary_page/workPlan/workPlan.js
import {getRotation,getPropertyWorkPlanType} from "../../apis/workPlanAndCompletion"
 import planning from "../../conmon/constants"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    commId:"",
    pwppId:"",
    topItem:"筛选",
    show:false,//弹出层
    animation:"",
    outColor:"",
    state:false,
    isactive:2,//工作项
    planningCycleData:[
      {
        id:1,
        name:'全部',
        enum:'ALL'
      },
      {
        id:2,
        name:'近一年',
        enum:'A_YEAR'
      },
      {
        id:3,
        name:'近一季度',
        enum:'FIRST_QUARTER'
      },
      {
        id:4,
        name:'近一个月',
        enum:'ONE_MONTH'
      },
      {
        id:5,
        name:'近一周',
        enum:'A_WEEK'
      }
    ],//计划周期
    planClassification:[
      {
        id:1,
        name:"全部"
      },
      {
        id:1,
        name:"工程"
      },
      {
        id:1,
        name:"安防"
      },
      {
        id:1,
        name:"服务"
      }, {
        id:1,
        name:"环境"
      }
    ],//计划分类
    sort:[
      {
        id:1,
        name:"默认",
        enum:"DEFAULT"
      },
      {
        id:1,
        name:"升序",
        enum:"ASC"
      },
      {
        id:1,
        name:"降序",
        enum:"DESC"
      }
    ],//排序
    planningCycleDataCurrentIndex:4,
    planClassificationCurrentIndex:2,
    sortCurrentIndex:1,
    planningCycleItem:"ALL",
    planClassificationItem:'ALL',
    sortItem:'DEFAULT',
    propertyWorkPlanToStore:[],//工作计划数据
    propertyWorkPlanData:[],//工作计划
  },
  //点击计划周期
  clickView(e){
    if(e.currentTarget.dataset.state == 'zhouqi'){
      this.setData({
        planningCycleDataCurrentIndex:e.currentTarget.dataset.index,
        planningCycleItem:this.data.planningCycleData[e.currentTarget.dataset.index-1].enum
      })
    }else  if(e.currentTarget.dataset.state == 'fenlei'){
      this.setData({
        planClassificationCurrentIndex:e.currentTarget.dataset.index,
        planClassificationItem:this.data.planClassification[e.currentTarget.dataset.index-1].pwptEnum
      })
    }else  if(e.currentTarget.dataset.state == 'paixu'){
      this.setData({
        sortCurrentIndex:e.currentTarget.dataset.index,
        sortItem:this.data.sort[e.currentTarget.dataset.index-1].enum
      })
    }
      
  },
  // 下拉框
  showPopup() {
    if(!this.data.show){
      this.setData({
        show: true ,
        topItem:"收起"
       });
    }else{
      this.setData({
        show: false ,
        topItem:"筛选",
        planningCycleDataCurrentIndex:4,
        planClassificationCurrentIndex:2,
        sortCurrentIndex:1,
       });
    }
   
  },

  onClose() {
    this.setData({ 
      show: false,
      topItem:"筛选",
      planningCycleDataCurrentIndex:4,
      planClassificationCurrentIndex:2,
      sortCurrentIndex:1,
     });
  },


  // 重置按钮
  resetClick(){
    this.setData({
      planningCycleDataCurrentIndex:1,
      planClassificationCurrentIndex:1,
      sortCurrentIndex:1
    })
  },

  //确定按钮
  determineClick(){
    this.setData({ 
      show: false,
      topItem:"筛选"
     });
  
     //发送请求查询数据
        //调用获取工作计划
    this.getRotation(this.data.commId,this.data.pwppId,this.data.planningCycleItem,this.data.planClassificationItem,this.data.sortItem);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
        commId:options.commId,
        pwppId:options.pwppId
    })
      //调用获取工作计划
      this.getRotation(options.commId,options.pwppId,this.data.planningCycleItem,this.data.planClassificationItem,this.data.sortItem);
      //调用获取工作计划类型
      this.getPropertyWorkPlanType();
  },
  //获取工作计划
  getRotation(commId,pwppId,planningCycleItem,planClassificationItem,sortItem){
    
    getRotation(commId,pwppId,planningCycleItem,planClassificationItem,sortItem).then((res)=>{
      if(res.code == 200){
          this.setData({
            propertyWorkPlanToStore:res.obj,
            propertyWorkPlanData:res.obj.ongoings
          })
      }
    })
  },
  //获取工作计划类型
  getPropertyWorkPlanType(){
    getPropertyWorkPlanType().then((res)=>{
      if(res.code == 200){
          this.setData({
            planClassification:res.obj
          })
      }
    })
  },

  changeAnimation(){
    this.setData({
      // state:true
    })
  },
  changeAnimation1(e){
    if(e.currentTarget.dataset.index == 1){
      this.setData({
        // state:true,
        isactive:e.currentTarget.dataset.index,
        propertyWorkPlanData:this.data.propertyWorkPlanToStore.all
      });
    }else if(e.currentTarget.dataset.index == 2){
      this.setData({
        // state:true,
        isactive:e.currentTarget.dataset.index,
        propertyWorkPlanData:this.data.propertyWorkPlanToStore.ongoings
      });
    }else if(e.currentTarget.dataset.index == 3){
      this.setData({
        // state:true,
        isactive:e.currentTarget.dataset.index,
        propertyWorkPlanData:this.data.propertyWorkPlanToStore.completes
      });
    }
   
    setTimeout(() => {
      this.setData({
        // state:false
      })
    }, 500);
  },
  endAnimation(){
    this.setData({
      state:false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})